/*This Project Impements the features of List in Python using Linked Lists of C*/
#include<stdio.h>
#include<stdlib.h>


int size_numbers_entered;

   struct global_node
   {
      int value;
      struct global_node *next;
   };
   
struct global_node *first_node=NULL;



struct global_node * display()
{
    struct global_node *p;

    printf("The list is  \n");
    printf("[ \t");

    for(p = first_node; p != NULL ; p = p->next) {
        printf("%d",p->value);
    }
    
    printf("\t ]");
}
   
 struct global_node *add_values(int number_to_add)
{

    struct global_node *new_node;                           //We take a new node having the same instance as that of the struct global_node and make 
                                                           //It point its value to the number to add .  
           
    new_node=malloc(sizeof(struct global_node));
    
    if(new_node==NULL)
    {
       printf("The space is not allocated");
    }
    
    
    new_node -> value = number_to_add;
    new_node -> next = first_node;  
    first_node = new_node;       
    
}

struct global_node * append()

{
       int number_to_append;
       printf("Enter the element you want to append :");
       scanf("%d",&number_to_append);
       first_node = add_values(first_node,number_to_append);
       display();
       
}



// The only difference between append and extend function is the number of elements you are inputing

struct global_node * extend ()
{
      int number,num,i;
      
      printf("Enter the number of elements you want to extend \n");
      scanf("%d",&number);
      printf("Enter the elements \n");
      
      for(i=0;i<number;i++)
      {
          scanf("%d",&num);
          first_node=add_values(first_node,num);
      }
      display();
}

struct global_node *search()

{
    int number;
    struct global_node *pointer_used_to_find_the_elemente  ; 
    
    printf("Enter the element you want you search \n ");
    scanf("%d",&number);
    pointer_used_to_find_the_element=first_node;
    
    for(p=first_node;p!=NULL;p=p->next){
       if(pointer_used_to_find_the_element -> value == n){
           
           printf("The element you were searching for exists in the list \n ");
   }
}
}




struct global_node * remove()
{
        int number;
        struct global_node *previous,*current;
        
        printf("Enter the element you want to remove \n");
        scanf("%d",&number);
        
        previous = NULL;
        current = first_node;
        
        for(; current!=NULL && current -> value != number ; p = p -> next, q = q->next)
        {
        if(q==NULL){
            return first_node;
        }
        if(p==NULL){
           first_node = first_node->next;
        }
        else            { 
           p->next = q->next;
        }
        free(p);
        display();   
     }
}

struct global_node * pop()
{
    int index_number,count=0;
    struct global_node *previous,*current;
    
    printf("Enter the index of the element u want to remove  \n ");
    scanf("%d",&index_number);
    
    count = index_number; 
    
    for(previous = NULL, current = first_node; current!=NULL  ;previous = previous -> next,current = current->next) {
      count=count+1;
    }
    if(current == NULL)
    {
       printf("The element you are looking for does not exist in the list \n");
    }
    if(q->value == index_number)
        { 
           p -> next = q->next;
        }
    free(p);
    display();
    return
}



struct global_node * insert(struct global_node *first_node)
{
    struct global_node *p,*q;
    int s,count=0;
    printf("enter the position where u want to insert : ");
    scanf("%d",&s);
    for(p=NULL,q=first_node;q!=NULL;p=p->next,q=q->next)
    {
       count=count+1;
        if(count==s)
        {
        }
    }
}     

struct global_node * indexx()
{
    int count=0,number_whose_frequency;
    struct global_node *p;
    
    printf("enter the element whose index u want to find : ");
    scanf("%d",&number_whose_frequency);
    
    for( p = first_node;p != NULL && p->value != number_whose_frequency; p = p->next)
    {
       count=count+1;  
    }
    if(p == NULL)
    {
       printf("Element not found\n");
    }
    if(p -> value == number_whose_frequency)
    {
       printf("The index of the element you are looing for is  %d ",count);
    }
}





 

struct global_node * count(struct global_node *first_node)
{}

struct global_node * reverse(struct global_node *first_node)
{}


struct global_node * sort(struct global_node *first_node)
{}


int main()
{
   
   int option,i,number_input;

   
   printf("Enter the number of elements you want to enter :");
   scanf("%d",&size_numbers_entered);
  
  
   for(i = 0;i<size_numbers_entered; i++)
   {
       printf("Enter an number\t");
       scanf("%d", &number_input);      
       first_node = add_values(first_node,number_input);
   }

   printf("Your list is of size %d",size_numbers_entered);
   
   printf("Your list is ");
   display();
        
   printf(" Which function do you want to implement - \n ");
   printf(" \n------------------------------------------------------------------------------------------ \n");
   printf("       	           0)        Display\n");
   printf("                   1)        Append\n");
   printf("                   2)        Extend\n");
   printf("                   3)        Pop\n");
   printf("                   4)        Remove\n");
   printf("                   5)        Index\n");
   printf("                   6)        Insert\n");
   printf("                   7)        list_size\n");
   printf("                   8)        Sort\n");
   printf("                   9)        Reverse\n");
   printf("                   10        Count\n");
   printf("                   11)       Check if value in list\n");
   printf("                   12)       Add more values\n");
   printf("                   13)       Exit\n");
		
		printf
		    (" \n    ------------------------------------------------------------------------------------------   \n  ");

		printf("\t\t\t\t Please enter an option \t");
   scanf("%d",&option);


   switch(option)
   {
       case 1 :append();
               break;
       case 2 :extend();
               break;
       case 3 :insert();
               break;
       case 4 :indexx();
               break;
       case 5 :pop();
               break;
       case 6 :delete();
               break;
       case 7 :reverse();
               break;
       case 8 :count();
               break;
       case 9 :sort();
                break; 
   }

}

